#include <vector>
#include <set>
#include <iostream>
#include <unordered_map>
using namespace std;


int findShortestSubArray(vector<int>& nums) {
    int f[10][4] = {}; int max = 0; int minlen = 50000;
    for(int num : nums){
        f[num][0]++;
        if(f[num][0] >= max){
            max = f[num][0];
        }
    }
    for(int i = 0; i < nums.size(); i++){
        if(f[nums[i]][0] == max){ f[nums[i]][1] = 1; }
        if(f[nums[i]][2] == 0){ f[nums[i]][2] = i+1; }
        if(f[nums[nums.size()-i-1]][3] == 0){ f[nums[nums.size()-i-1]][3] = nums.size()-i; }
    }
    for(int i = 0; i < nums.size(); i++){
        int diff = 0;
        if(f[nums[i]][1] == 1){
            diff = f[nums[i]][3] - f[nums[i]][2] + 1;
            if(minlen > diff){ minlen = diff; }
        }
    }
    return minlen;
}

int main(){
    // vector<int> nums = { 1,2,2,3,1,4,2 };
    vector<int> nums = { 2 };
    cout << findShortestSubArray(nums) << endl;
    return 0;
}